{extend name="base"/}
{block name="main"}
<div class="Hui-article">
    <article class="cl pd-20">
        <div class="n_tab_line">
            <a href="/admin/advert/AdvertList?ap_id={$ap_id}" class="n_tab_list">广告列表</a>
            <a href="/admin/advert/addAdvert?ap_id={$ap_id}" class="n_tab_add">添加广告</a>
            <a href="/admin/advert/index" class="n_tab_add">广告位列表</a>
            <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
            <div class="cl"></div>
        </div>
        <form class="Huiform" method="post" action="__CONF_SITE__admin/advert/AdvertList&ap_id={$ap_id}" target="_self">
            <div class="text-c"> 广告名称：
                <input type="text" class="input-text" value="{$adv_title}" style="width:250px" placeholder="输入广告名称"  name="adv_title">
                <button type="submit" class="btn btn-success"  name=""><i class="Hui-iconfont">&#xe665;</i> 搜广告</button>
            </div>
        </form>
        <table class="table table-border table-bordered table-hover table-bg">
            <thead>
            <tr>
                <th scope="col" colspan="9">广告列表</th>
            </tr>
            <tr class="text-c">
                <th>排序</th>
                <th>名称</th>
                <th>所属广告</th>
                <th>链接地址</th>
                <th>比例</th>
                <th>是否启用</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="list" id="vo"}
            <tr class="text-c">
                <td>{$vo['sort']}</td>
                <td>{$vo['adv_title']}</td>
                <td>{$vo['ap_name']}</td>
                <td>{$vo['adv_url']}</td>
                <td>{$vo['adv_width']}</td>
                {if condition="($vo['is_use'] == 1)"}
                <td><a href="javascript:;" onclick="setAdvertUse(this,'{$vo.adv_id}',0);"><i class="Hui-iconfont">&#xe6e1;</i></a></td>
                {else /}
                <td><a href="javascript:;" onclick="setAdvertUse(this,'{$vo.adv_id}',1);"><i class="Hui-iconfont">&#xe706;</i></a></td>
                {/if}
                <td class="td-manage">
                    <a title="编辑" href="javascript:;" onclick="advert_edit('广告编辑','updateAdvert?adv_id={$vo.adv_id}','800','600')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
                    <a title="删除" href="javascript:;" onclick="advert_del(this,'{$vo.adv_id}')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
    </article>
    <div class="n_page_no">
        {$page}
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    /*
     参数解释：
     title	标题
     url		请求的url
     w		弹出层宽度（缺省调默认值）
     h		弹出层高度（缺省调默认值）
     */
    /*规格-编辑*/
    function advert_edit(title,url,w,h){
        layer_show(title,url,w,h);
    }
    //启用与禁用
    function setAdvertUse(eve,adv_id,is_use){
        $.ajax({
            type : "post",
            url : "{:url('advert/setAdvertUse')}",
            data : {
                "adv_id" : adv_id,
                "is_use" : is_use
            },
            success : function(data) {
                if(data["code"] > 0 ){
                    if(is_use == 1){
                        layer.msg("启用成功", {icon: 1, time: 1000});
                        $(eve).addClass('active').attr('onclick','setAdvertUse(this,'+adv_id+',0)').html('<i class="Hui-iconfont">&#xe6e1;</i>');
                    }else{
                        layer.msg("禁用成功", {icon: 1, time: 1000});
                        $(eve).addClass('active').attr('onclick','setAdvertUse(this,'+adv_id+',1)').html('<i class="Hui-iconfont">&#xe706;</i>');
                    }
                }else{
                    layer.msg(data['message'], {icon: 5, time: 1000});
                }
            }
        })
    }
    function advert_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //此处请求后台程序，下方是成功后的后台处理……
            //删除
            $.ajax({
                type : "post",
                url : "{:url('advert/delAdvert')}",
                data : {
                    "adv_id" : id,
                },
                success : function(data) {
                    if (data['code'] > 0) {
                        $(obj).parents("tr").remove();
                        layer.msg(data['message'],{icon:1,time:1000});
                    }else{
                        layer.msg(data['message'], {icon: 2, time: 1000});
                    }
                }
            })
        });
    }
</script>
{/block}